*File: div_gov_analysis_stathis_data_ssh.do
*Purpose: Data Analysis for Divided Government Paper looking at Stathis data

clear all
set more off

cap cd "~/div_gov"

*Load formatted data

import delimited using data/Stathis_LandMarkLegDataCombined112514.csv, clear
gen n = 1
collapse (count) stathis_sigact_n=n, by(congress)
merge 1:1 congress using data/congress_data.dta
keep if _m==3
drop _m

drop sigact_n student lag_sigact d_sigact ln_sigact_n ln_lag_sigact ln_d_sigact

ren stathis_sigact_n sigact_n
gen lag_sigact = sigact_n[_n-1] if cong!=cong[_n-1]
gen d_sigact = sigact_n - lag_sigact
gen ln_sigact_n = log(sigact_n+1)
gen ln_lag_sigact = log(lag_sigact+1)
gen ln_d_sigact = ln_sigact_n - ln_lag_sigact

save data/congress_data_stathis, replace

use data/congress_data_stathis, clear
*Check mean levels of total and significant acts by "era" (pre/post 1900)
sum sigact_n pub_acts if congress<=55
sum sigact_n pub_acts if congress>55

*Summary Statistics

*Table 1
*Create Table of Significant and Total Legislation made Under Divided Gov and Unified Gov.
gen sigact_n_sd = sigact_n
gen pub_acts_sd = pub_acts

collapse (mean) sigact_n pub_acts (sd) sigact_n_sd pub_acts_sd (count) priv_acts, by(unified_g)

outsheet using "figs_ssh/stathis_analysis/table1_stathis.csv", comma replace

*Table 2

use data/congress_data_stathis, clear

*Generate Unified Gov Dummy Variable
gen unified = "Divided" if unified_g == 0
replace unified = "Unified" if unified_g == 1

collapse (mean) sigact_n pub_acts (count) priv_acts, by(period unified)
rename priv_acts obs
outsheet using "figs_ssh/stathis_analysis/table2_stathis.csv", comma replace
egen time_period = group(period)
label define time 1 "1789-1861" 2 "1862-1899" 3 "1900-1946" 4 "1947-2010"
label values time_period time

*Table 3
use "data/congress_data_stathis.dta", clear

*Select Decade to omit (Use first Congress as base line?)
char decade[omit] 1780

gen time = congress
gen time_2 = time^2

label var time "Time"
label var time_2 "Time Squared"

local spec1 unified_g
local spec2 `spec1' i.period
local spec3 `spec2' i.president
local spec4 `spec2' i.decade

estimates clear
forvalues n = 1(1)4{
//xi: reg pub_acts `spec`n'', robust
//estimates store pub_`n'
xi: reg sigact_n `spec`n'', robust
estimates store sig_`n'

xi: reg sigact_n `spec`n'' if congress<=79, robust
estimates store early_`n'

//xi: reg ln_pub_acts `spec`n'', robust
//estimates store ln_pub_`n'
xi: reg ln_sigact_n `spec`n'', robust
estimates store ln_sig_`n'
}

esttab sig* early* using "figs_ssh/stathis_analysis/table3_stathis.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
indicate("President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Significant Legislation in Divided/Unified Government \label{tab3stathis}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("All Congresses" "1st-79th Congresses", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab sig* early* using "figs_ssh/stathis_analysis/table3_stathis.csv", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
indicate("President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Significant Legislation in Divided/Unified Government \label{tab3stathis}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("All Congresses" "1st-79th Congresses", pattern(1 0 0 0 1 0 0 0)) nomtitles replace

esttab ln_sig* using "figs_ssh/stathis_analysis/table3log_stathis.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
indicate("President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g _Iperiod* ) ///
addnotes("Robust Standard Errors" "We transformed the outcome variable for log(Significant Legislation) by adding" "one to address the one instance where a Congress produced no significant legislation.") ///
r2 se compress title("Divided/Unified Government and log(Legislative Output) \label{tab3logstathis}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("log(Total Legislation)" "log(Significant Legislation)", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace


*Additional Figures for Presentation

esttab sig_2 sig_3 sig_4 using "figs_ssh/stathis_analysis/table3sig_stathis.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
indicate("President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government and Legislative Output (Significant Legislation) \label{tab3sigstathis}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Significant Legislation", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

estimates clear

*APPENDIX TABLE FOR PRE AND POST 1900

forvalues n = 1(1)4{
//xi: reg pub_acts `spec`n'' if congress<=55, robust
//estimates store pre_pub_`n'
xi: reg sigact_n `spec`n'' if congress<=55, robust
estimates store pre_sig_`n'

//xi: reg pub_acts `spec`n'' if congress>55, robust
//estimates store post_pub_`n'
xi: reg sigact_n `spec`n'' if congress>55, robust
estimates store post_sig_`n'
}

esttab pre_sig* using "figs_ssh/stathis_analysis/table3_1_55_stathis.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
indicate("President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government and Legislative Output, Before 1900 \label{tab3astathis}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab post_sig* using "figs_ssh/stathis_analysis/table3_56_111_stathis.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
indicate("President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government and Legislative Output, 1900 and After \label{tab3bstathis}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

estimates clear

*APPENDIX TABLE THAT INCLUDES SPEC WITH TIME TREND
local spec1 unified_g
local spec2 `spec1' time time_2
local spec3 `spec2' i.president
local spec4 `spec2' i.decade

forvalues n = 1(1)4{
//xi: reg pub_acts `spec`n'', robust
//estimates store pub_`n'
xi: reg sigact_n `spec`n'', robust
estimates store sig_`n'
}

esttab sig* using "figs_ssh/stathis_analysis/table_app_time_trend_stathis.tex", b(%9.2f) label ///
indicate("Time Trend (Polynomial) = time" "President FEs = _Ipres*" "Decade FEs = _Idec*" ) keep(unified_g) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government and Legislative Output with Time Trend \label{tabtimetrendstathis}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

estimates clear

*Appendix Table
*Test of patterns w/ in Unified Gov

foreach var of varlist  time_since* {
gen ln_`var' = log(`var')
}

label var ln_time_since_unif "log(Time Since Pres. Party Held Unified Control)"
label var ln_time_since_unif_opp "log(Time Since Party Opposing Pres. Held Unified Control)"
label var ln_time_since_div "log(Time Since Divided Government)"

local spec1 ln_time_since_unif ln_time_since_unif_opp ln_time_since_div //house_maj_pct sen_maj_pct
local spec2 `spec1' i.period

forvalues n = 1(1)2{
//xi: reg pub_acts `spec`n'' if unified_g == 1, robust
//estimates store pub_`n'
xi: reg sigact_n `spec`n'' if unified_g == 1, robust
estimates store sig_`n'
}

esttab sig* using "figs_ssh/stathis_analysis/table_app_stathis.tex", b(%9.2f) indicate("Time Period Controls = _Iperiod*" ) ///
drop(_cons ) addnotes("Robust Standard Errors" ) label r2 se compress title("Determinants of Productivity under Unified Government \label{tabdetstathis}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

estimates clear

*Table 4
use "data/congress_data_stathis.dta", clear
 
tsset congress

local specb1 d_u_g
local specb2 `specb1' L.d_pubact
local specb3 `specb1' i.period

local specc1 d_u_g
local specc2 `specb1' L.d_sigact
local specc3 `specc1' i.period

local ln_specb1 d_u_g
local ln_specb2 `ln_specb1' L.ln_d_pubact
local ln_specb3 `ln_specb1' i.period

local ln_specc1 d_u_g
local ln_specc2 `ln_specb1' L.ln_d_sigact
local ln_specc3 `ln_specc1' i.period

/*
forvalues n = 1(1)3{
xi: reg d_pubact `specb`n'', robust
estimates store pub_`n'
xi: reg d_pubact `specb`n'' if congress<=55, robust
estimates store pre_pub_`n'
xi: reg d_pubact `specb`n'' if congress>55, robust
estimates store post_pub_`n'

xi: reg ln_d_pubact `ln_specb`n'', robust
estimates store ln_pub_`n'
xi: reg ln_d_pubact `ln_specb`n'' if congress<=55, robust
estimates store ln_pre_pub_`n'
xi: reg ln_d_pubact `ln_specb`n'' if congress>55, robust
estimates store ln_post_pub_`n'
}
*/

forvalues n = 1(1)3{
xi: reg d_sigact `specc`n'', robust
estimates store sig_`n'
xi: reg d_sigact `specc`n'' if congress<=55, robust
estimates store pre_sig_`n'
xi: reg d_sigact `specc`n'' if congress>55, robust
estimates store post_sig_`n'

xi: reg ln_d_sigact `ln_specc`n'', robust
estimates store ln_sig_`n'
xi: reg ln_d_sigact `ln_specc`n'' if congress<=55, robust
estimates store ln_pre_sig_`n'
xi: reg ln_d_sigact `ln_specc`n'' if congress>55, robust
estimates store ln_post_sig_`n'
}

label var d_u_g "$\Delta$ Unified Gov."
esttab sig* pre_sig* post_sig* using "figs_ssh/stathis_analysis/table4_stathis.tex", b(%9.2f) indicate("Lagged DV = *act*" "Time Period Controls = _Iperiod*") keep(d_u_g _cons) r2 se label compress ///
title("$\Delta$ Significant Legislation \label{tab4stathis}") star(* 0.10 ** 0.05 *** 0.01) drop(_cons ) addnotes("Robust Standard Errors") ///
mgroups("All Congresses" "1st-55th Congresses" "56th-111th Congresses", pattern(1 0 0 1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab sig* pre_sig* post_sig* using "figs_ssh/stathis_analysis/table4_stathis.csv", b(%9.2f) indicate("Lagged DV = *act*" "Time Period Controls = _Iperiod*") keep(d_u_g _cons) r2 se label compress ///
title("$\Delta$ Significant Legislation \label{tab4stathis}") star(* 0.10 ** 0.05 *** 0.01) drop(_cons ) addnotes("Robust Standard Errors") ///
mgroups("All Congresses" "1st-55th Congresses" "56th-111th Congresses", pattern(1 0 0 1 0 0 1 0 0)) nomtitles replace

esttab ln_sig* using "figs_ssh/stathis_analysis/table4log_stathis.tex", b(%9.2f) indicate("Lagged DV = *act*" "Time Period Controls = _Iperiod*") keep(d_u_g _cons) r2 se label compress ///
title("Changes in Divided/Unified Government and log(Legislative Output) \label{tab4logstathis}") star(* 0.10 ** 0.05 *** 0.01) drop(_cons ) addnotes("Robust Standard Errors") ///
mgroups("$\Delta$ log(Total Legislation)" "$\Delta$ log(Significant Legislation)", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab ln_pre_sig* using "figs_ssh/stathis_analysis/table4log_1_55_stathis.tex", b(%9.2f) indicate("Lagged DV = *act*" "Time Period Controls = _Iperiod*") keep(d_u_g _cons) r2 se label compress ///
title("Changes in Divided/Unified Government and log(Legislative Output), Before 1900 \label{tab4alogstathis}") star(* 0.10 ** 0.05 *** 0.01) drop(_cons ) addnotes("Robust Standard Errors") ///
mgroups("$\Delta$ log(Total Legislation)" "$\Delta$ log(Significant Legislation)", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

esttab * ln_post_sig* using "figs_ssh/stathis_analysis/table4log_56_111_stathis.tex", b(%9.2f) indicate("Lagged DV = *act*" "Time Period Controls = _Iperiod*") keep(d_u_g _cons) r2 se label compress ///
title("Changes in Divided/Unified Government and log(Legislative Output), 1900 and After \label{tab4blogstathis}") star(* 0.10 ** 0.05 *** 0.01) drop(_cons ) addnotes("Robust Standard Errors") ///
mgroups("$\Delta$ log(Total Legislation)" "$\Delta$ log(Significant Legislation)", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace

estimates clear

*More Appendix Tables 
*(Supermajorities)

use "data/congress_data_stathis.dta", clear

gen super_unif = unified_g * supermajority
label var super_unif "Unified Government x Supermajority"

local spec1 unified_g supermajority super_unif
local spec2 `spec1' i.period

forvalues n = 1(1)2{
xi: reg pub_acts `spec`n'' if year>=1917, robust
estimates store pub_`n'
xi: reg sigact_n `spec`n'' if year>=1917, robust
estimates store sig_`n'
}

esttab pub* sig* using "figs_ssh/stathis_analysis/supermaj_table-stathis.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
keep(unified_g supermajority super_unif _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government, Senate Supermajorities and Legislative Output, 1917-2010 \label{tabsupermajstathis}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace
 
estimates clear

**Deficit Spending


gen lag_deficit_unif = unified_g * lag_deficit
label var lag_deficit_unif "Unified Government x Deficit (Lagged)"

local spec1 unified_g lag_deficit lag_deficit_unif
local spec2 `spec1' i.period

forvalues n = 1(1)2{
xi: reg pub_acts `spec`n'' if year>=1901, robust
estimates store pub_`n'
xi: reg sigact_n `spec`n'' if year>=1901, robust
estimates store sig_`n'
}

esttab pub* sig* using "figs_ssh/stathis_analysis/deficit_table_stathis.tex", b(%9.2f) label coeflabels(_Iperiod_2 "37th-55th Congress" _Iperiod_3 "56th-79th Congress" _Iperiod_4 "80th-111th Congress" _cons "Constant") ///
keep(unified_g lag_deficit lag_deficit_unif _Iperiod* ) addnotes("Robust Standard Errors" ) r2 se compress title("Divided/Unified Government, the Budget Deficit and Legislative Output, 1901-2010 \label{tabdeficitstathis}") ///
star(* 0.10 ** 0.05 *** 0.01) mgroups("Total Legislation" "Significant Legislation", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitles replace
 
estimates clear
